import {NodeTypes} from "../NodeTypes";
import {EStatus} from "../EStatus";

export class Sequences {
    type: NodeTypes.Sequences
    public children: Array<any>

    initializer() {
        console.log("初始化");
    }

    action(context) {
        let status: number;
        for (let i = 0; i < this.children.length; i++) {
            const node = this.children[i];
            switch (node.type) {
                case NodeTypes.Leaf:
                    status = node.action(context);
                    break;
                case NodeTypes.Sequences:
                    status = node.action(context);
                    break;
                case NodeTypes.Selector:
                    status = node.action(context);
                    break;
                default:
                    status = node.action(context);
            }
            //任意一个出错 立马返回失败
            if (status === EStatus.Failure)
                return EStatus.Failure;
        }
        return status;
    }
}